import logging
from flask import Flask, request
from module.auth.user import user_bp
from module.order.rule import rule_bp

# 配置日志
logging.basicConfig(
    level=logging.INFO,  # 设置日志级别为 INFO
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',  # 日志格式
    handlers=[
        logging.FileHandler('app.log'),  # 日志写入文件
        logging.StreamHandler()  # 日志输出到控制台
    ]
)
logger = logging.getLogger(__name__)

app = Flask(__name__)
app.register_blueprint(user_bp)
app.register_blueprint(rule_bp)

@app.before_request
def before_request():
    logger.info(request.headers)
    if request.args:
        logger.info(request.args)
@app.route('/')
def hello_world():  # put application's code here
    logger.info("访问根路径 /")
    return 'Hello World!'

if __name__ == '__main__':
    logger.info("Flask 应用启动")
    app.run(host='0.0.0.0', port=5000)